package com.aspose.cells;

import java.util.HashMap;

class zqq {
   private static final com.aspose.cells.b.c.a.za a = new com.aspose.cells.b.c.a.za(new String[]{"D", "M", "Y", "YM", "YD", "MD"});

   static Object a(double var0, double var2) {
      double var4 = Math.ceil(var0 - var2);
      return var4;
   }

   static Object a(double var0, double var2, String var4, boolean var5) {
      if (var2 < var0) {
         return zst.f;
      } else {
         byte var19;
         DateTime var6;
         DateTime var7;
         int var10;
         int var11;
         switch(a.a(var4.toUpperCase())) {
         case 0:
            double var8 = Math.ceil(var2 - var0);
            if (var8 < 0.0D) {
               return zst.f;
            }

            return var8;
         case 1:
            try {
               var6 = CellsHelper.getDateTimeFromDouble(var0, var5);
               var7 = CellsHelper.getDateTimeFromDouble(var2, var5);
               var10 = var7.getDay() < var6.getDay() ? -1 : 0;
               return (double)((var7.getYear() - var6.getYear()) * 12 + var7.getMonth() - var6.getMonth()) + (double)var10;
            } catch (Exception var17) {
               return zst.i;
            }
         case 2:
            try {
               var6 = CellsHelper.getDateTimeFromDouble(var0, var5);
               var7 = CellsHelper.getDateTimeFromDouble(var2, var5);
               var19 = 0;
               if (var6.getMonth() > var7.getMonth()) {
                  var19 = -1;
               } else if (var6.getMonth() == var7.getMonth() && var6.getDay() > var7.getDay()) {
                  var19 = -1;
               }

               return (double)(var7.getYear() - var6.getYear()) + (double)var19;
            } catch (Exception var16) {
               return zst.i;
            }
         case 3:
            try {
               var6 = CellsHelper.getDateTimeFromDouble(var0, var5);
               var7 = CellsHelper.getDateTimeFromDouble(var2, var5);
               var10 = var7.getDay() < var6.getDay() ? -1 : 0;
               var11 = var7.getMonth() - var6.getMonth();
               if (var11 == 0 && var10 < 0) {
                  return 11.0D;
               }

               return (double)(var11 < 0 ? var11 + 12 + var10 : var11 + var10);
            } catch (Exception var15) {
               return zst.i;
            }
         case 4:
            try {
               var6 = CellsHelper.getDateTimeFromDouble(var0, var5);
               var7 = CellsHelper.getDateTimeFromDouble(var2, var5);
               var19 = 0;
               if (var6.getMonth() > var7.getMonth()) {
                  var19 = -1;
               } else if (var6.getMonth() == var7.getMonth() && var6.getDay() > var7.getDay()) {
                  var19 = -1;
               }

               var11 = var7.getYear() - var6.getYear() + var19;
               var6 = var6.addYears(var11);
               int var12 = var7.getYear();
               byte var13 = 0;
               if ((var12 % 400 == 0 || var12 % 4 == 0 && var12 % 100 != 0) && var7.getMonth() >= 3) {
                  if (var7.getYear() == var6.getYear()) {
                     if (var6.getMonth() == 2 && var6.getDay() == 1) {
                        var13 = 1;
                     } else if (var6.getMonth() == 1) {
                        var13 = 1;
                     }
                  } else if (var7.getYear() > var6.getYear()) {
                     var13 = 1;
                  }
               }

               return var2 - CellsHelper.getDoubleFromDateTime(var6, var5) - (double)var13;
            } catch (Exception var18) {
               return zst.i;
            }
         case 5:
            try {
               var6 = CellsHelper.getDateTimeFromDouble(var0, var5);
               var7 = CellsHelper.getDateTimeFromDouble(var2, var5);
               var10 = var7.getDay() < var6.getDay() ? -1 : 0;
               var11 = (var7.getYear() - var6.getYear()) * 12 + var7.getMonth() - var6.getMonth() + var10;
               var6 = var6.addMonths(var11);
               return var2 - CellsHelper.getDoubleFromDateTime(var6, var5);
            } catch (Exception var14) {
               return zst.i;
            }
         default:
            return zst.f;
         }
      }
   }

   static double a(int var0, DateTime var1) {
      int var2 = var1.getDayOfWeek();
      switch(var0) {
      case 2:
         if (var2 == 0) {
            return 7.0D;
         }

         return (double)var2;
      case 3:
         --var2;
         if (var2 < 0) {
            return 6.0D;
         }

         return (double)var2;
      default:
         return (double)(var2 + 1);
      }
   }

   static Object a(int var0, Object var1, WorkbookSettings var2) {
      var1 = zyn.a(var1, var2);
      if (var1 instanceof zst) {
         return var1;
      } else {
         double var3 = (Double)var1;
         if (var3 >= 0.0D && var3 <= 2958465.99D) {
            if (var3 == 0.0D) {
               switch(var0) {
               case 0:
                  return 0.0D;
               case 1:
                  return 1.0D;
               case 2:
                  return 1900.0D;
               case 3:
                  return 0.0D;
               case 4:
                  return 0.0D;
               case 5:
                  return 0.0D;
               default:
                  return zst.i;
               }
            } else {
               DateTime var5 = CellsHelper.getDateTimeFromDouble(var3, var2.getDate1904());
               switch(var0) {
               case 0:
                  return (double)var5.getDay();
               case 1:
                  return (double)var5.getMonth();
               case 2:
                  return (double)var5.getYear();
               case 3:
                  return (double)var5.getSecond() + (double)(var5.getMillisecond() > 500 ? 1 : 0);
               case 4:
                  return (double)var5.getMinute();
               case 5:
                  return (double)var5.getHour();
               default:
                  return zst.i;
               }
            }
         } else {
            return zst.f;
         }
      }
   }

   static double a(DateTime var0, int var1) {
      DateTime var2 = new DateTime(var0.addDays(-a(0, var0.addDays(-1.0D)) + 4.0D).getYear(), 1, 3);
      return (double)((int)(((double)com.aspose.cells.a.c.zk.e(var0, var2).b() + a(0, var2) + 5.0D) / 7.0D));
   }

   static double b(DateTime var0, int var1) {
      DateTime var2 = new DateTime(var0.getYear(), 1, 1);
      int var3 = var2.getDayOfWeek();
      if (var1 == 21) {
         return a(var0, var1);
      } else {
         com.aspose.cells.b.a.zk var4 = com.aspose.cells.a.c.zk.e(var0, var2);
         int var5 = (int)var4.c() + 1;
         byte var6 = 0;
         switch(var1) {
         case 2:
         case 11:
         case 21:
            var6 = 1;
         case 3:
         case 4:
         case 5:
         case 6:
         case 7:
         case 8:
         case 9:
         case 10:
         case 17:
         case 18:
         case 19:
         case 20:
         default:
            break;
         case 12:
            var6 = 2;
            break;
         case 13:
            var6 = 3;
            break;
         case 14:
            var6 = 4;
            break;
         case 15:
            var6 = 5;
            break;
         case 16:
            var6 = 6;
         }

         boolean var7 = false;
         int var9;
         if (var6 == var3) {
            var9 = 7;
         } else if (var6 < var3) {
            var9 = 7 - (var3 - var6);
         } else {
            var9 = var6 - var3;
         }

         var5 -= var9;
         if (var5 <= 0) {
            return 1.0D;
         } else {
            int var8 = var5 / 7 + 1;
            if (var5 % 7 != 0) {
               ++var8;
            }

            return (double)var8;
         }
      }
   }

   static boolean a(DateTime var0, DateTime var1, double var2, double var4) {
      if (var2 == var4) {
         return true;
      } else if (var4 - var2 > 7.0D) {
         return false;
      } else {
         int var6 = var0.getDayOfWeek();
         int var7 = var1.getDayOfWeek();
         return var6 < var7;
      }
   }

   static DateTime c(DateTime var0, int var1) {
      switch(var0.getDayOfWeek()) {
      case 0:
         if (var1 > 5) {
            var0 = var0.addDays((double)(var1 + 2));
         } else if (var1 == 0) {
            var0 = var0.addDays(1.0D);
         } else {
            var0 = var0.addDays((double)var1);
         }
         break;
      case 5:
         var0 = var0.addDays((double)(var1 + 2));
         break;
      case 6:
         if (var1 == 0) {
            var0 = var0.addDays(2.0D);
         } else {
            var0 = var0.addDays((double)(var1 + 1));
         }
         break;
      default:
         int var2 = 6 - var0.getDayOfWeek();
         if (var2 > var1) {
            var0 = var0.addDays((double)var1);
         } else {
            var0 = var0.addDays((double)(var1 + 2));
         }
      }

      return var0;
   }

   static DateTime d(DateTime var0, int var1) {
      switch(var0.getDayOfWeek()) {
      case 0:
         var0 = var0.addDays((double)(-(var1 + 1)));
         break;
      case 1:
         var0 = var0.addDays((double)(-(var1 + 2)));
         break;
      case 6:
         var0 = var0.addDays((double)(-var1));
         break;
      default:
         int var2 = var0.getDayOfWeek();
         if (var2 > var1) {
            var0 = var0.addDays((double)(-var1));
         } else {
            var0 = var0.addDays((double)(-(var1 + 2)));
         }
      }

      return var0;
   }

   static Object a(DateTime var0, int var1, Object var2, DateTime[] var3) {
      if (var2 instanceof Integer) {
         int var4 = (Integer)var2;
         switch(var4) {
         case 1:
            return a(var0, var1, "0000011", var3);
         case 2:
            return a(var0, var1, "1000001", var3);
         case 3:
            return a(var0, var1, "1100000", var3);
         case 4:
            return a(var0, var1, "0110000", var3);
         case 5:
            return a(var0, var1, "0011000", var3);
         case 6:
            return a(var0, var1, "0001100", var3);
         case 7:
            return a(var0, var1, "0000110", var3);
         case 8:
         case 9:
         case 10:
         default:
            return 0;
         case 11:
            return a(var0, var1, "0000001", var3);
         case 12:
            return a(var0, var1, "1000000", var3);
         case 13:
            return a(var0, var1, "0100000", var3);
         case 14:
            return a(var0, var1, "0010000", var3);
         case 15:
            return a(var0, var1, "0001000", var3);
         case 16:
            return a(var0, var1, "0000100", var3);
         case 17:
            return a(var0, var1, "0000010", var3);
         }
      } else {
         return a(var0, var1, (String)var2, var3);
      }
   }

   static Object a(DateTime var0, int var1, String var2, DateTime[] var3) {
      int var4 = 0;
      boolean[] var5 = new boolean[7];
      if (var2.charAt(0) == '1') {
         ++var4;
         var5[1] = true;
      }

      if (var2.charAt(1) == '1') {
         ++var4;
         var5[2] = true;
      }

      if (var2.charAt(2) == '1') {
         ++var4;
         var5[3] = true;
      }

      if (var2.charAt(3) == '1') {
         ++var4;
         var5[4] = true;
      }

      if (var2.charAt(4) == '1') {
         ++var4;
         var5[5] = true;
      }

      if (var2.charAt(5) == '1') {
         ++var4;
         var5[6] = true;
      }

      if (var2.charAt(6) == '1') {
         ++var4;
         var5[0] = true;
      }

      DateTime var6 = var0;
      DateTime var7 = var0.addDays((double)var1);
      double var8 = (double)var1;
      double var10 = 0.0D;
      double var12 = 0.0D;
      if (var1 > 0) {
         if (!var5[var0.getDayOfWeek()]) {
            ++var8;
         }
      } else if (!var5[var0.getDayOfWeek()]) {
         --var8;
      }

      do {
         var10 = (Double)a(var6, var7, var2, var3, false);
         if (var10 == 0.0D) {
            var7 = var7.addDays(var12);
            break;
         }

         var12 = var8 - var10;
         var6 = var7;
         if (var5[var7.getDayOfWeek()]) {
            --var8;
         }

         var7 = var7.addDays(var12);
         var8 = var8 - var10 + 1.0D;
      } while(var12 > 0.0D);

      return var7;
   }

   static Object a(DateTime var0, int var1, DateTime[] var2) {
      int var4;
      HashMap var6;
      int var7;
      int var8;
      if (var1 > 0) {
         var0.addDays((double)var1);
         var4 = var1 / 5;
         int var10 = var1 % 5;
         if (var10 == 0 && (var0.getDayOfWeek() == 0 || var0.getDayOfWeek() == 6)) {
            --var4;
            var10 = 5;
         }

         DateTime var9 = var0.addDays((double)(var4 * 7));
         var9 = c(var9, var10);
         if (var2 != null) {
            var6 = new HashMap();
            var7 = 0;

            while(var7 < var2.length) {
               switch(var2[var7].getDayOfWeek()) {
               default:
                  if (com.aspose.cells.a.c.zk.b(var2[var7], var0) && com.aspose.cells.a.c.zk.c(var2[var7], var9)) {
                     var8 = (int)CellsHelper.getDoubleFromDateTime(var2[var7], false);
                     if (var6.get(var8) == null) {
                        var6.put(var8, var8);
                        switch(var9.getDayOfWeek()) {
                        case 0:
                           var9 = var9.addDays(1.0D);
                           break;
                        case 5:
                           var9 = var9.addDays(3.0D);
                           break;
                        case 6:
                           var9 = var9.addDays(2.0D);
                           break;
                        default:
                           var9 = var9.addDays(1.0D);
                        }
                     }
                  }
               case 0:
               case 6:
                  ++var7;
               }
            }
         }

         return var9;
      } else {
         int var3 = -var1 / 5;
         var4 = -var1 % 5;
         DateTime var5 = var0.addDays((double)(-var3 * 7));
         var5 = d(var5, var4);
         if (var2 != null) {
            com.aspose.cells.b.a.za.a((Object[])var2);
            var6 = new HashMap();
            var7 = var2.length - 1;

            while(var7 >= 0) {
               switch(var2[var7].getDayOfWeek()) {
               default:
                  if (com.aspose.cells.a.c.zk.a(var2[var7], var5) && com.aspose.cells.a.c.zk.c(var2[var7], var0)) {
                     var8 = (int)CellsHelper.getDoubleFromDateTime(var2[var7], false);
                     if (var6.get(var8) == null) {
                        var6.put(var8, var8);
                        switch(var5.getDayOfWeek()) {
                        case 0:
                           var5 = var5.addDays(-2.0D);
                           break;
                        case 1:
                           var5 = var5.addDays(-3.0D);
                           break;
                        case 6:
                           var5 = var5.addDays(-1.0D);
                           break;
                        default:
                           var5 = var5.addDays(-1.0D);
                        }
                     }
                  }
               case 0:
               case 6:
                  --var7;
               }
            }
         }

         return var5;
      }
   }

   static Object a(DateTime var0, DateTime var1, Object var2, DateTime[] var3, boolean var4) {
      if (var2 instanceof Integer) {
         int var5 = (Integer)var2;
         switch(var5) {
         case 1:
            return a(var0, var1, "0000011", var3, var4);
         case 2:
            return a(var0, var1, "1000001", var3, var4);
         case 3:
            return a(var0, var1, "1100000", var3, var4);
         case 4:
            return a(var0, var1, "0110000", var3, var4);
         case 5:
            return a(var0, var1, "0011000", var3, var4);
         case 6:
            return a(var0, var1, "0001100", var3, var4);
         case 7:
            return a(var0, var1, "0000110", var3, var4);
         case 8:
         case 9:
         case 10:
         default:
            return 0;
         case 11:
            return a(var0, var1, "0000001", var3, var4);
         case 12:
            return a(var0, var1, "1000000", var3, var4);
         case 13:
            return a(var0, var1, "0100000", var3, var4);
         case 14:
            return a(var0, var1, "0010000", var3, var4);
         case 15:
            return a(var0, var1, "0001000", var3, var4);
         case 16:
            return a(var0, var1, "0000100", var3, var4);
         case 17:
            return a(var0, var1, "0000010", var3, var4);
         }
      } else {
         return a(var0, var1, (String)var2, var3, var4);
      }
   }

   static Object a(DateTime var0, DateTime var1, String var2, DateTime[] var3, boolean var4) {
      double var5 = (double)((int)CellsHelper.getDoubleFromDateTime(var0, var4));
      double var7 = (double)((int)CellsHelper.getDoubleFromDateTime(var1, var4));
      int var9 = (int)(var7 - var5 + 1.0D);
      boolean var10 = false;
      if (var9 < 0) {
         var9 = -var9;
         var10 = true;
         DateTime var11 = var0;
         var0 = var1;
         var1 = var11;
         var9 = (int)(var5 - var7 + 1.0D);
      }

      int var19 = 0;
      String var12 = var2;
      boolean[] var13 = new boolean[7];

      for(int var14 = 0; var14 <= 6; ++var14) {
         if (var12.charAt(var14) == '1') {
            ++var19;
            var13[var14] = true;
         }
      }

      var9 -= 7 - var0.getDayOfWeek();
      double var20 = 0.0D;
      switch(var0.getDayOfWeek()) {
      case 0:
         var20 += (double)(7 - var19);
         break;
      case 1:
         var20 += (double)(6 - var19);
         if (var13[6]) {
            ++var20;
         }
         break;
      case 2:
         var20 += (double)(5 - var19);
         if (var13[6]) {
            ++var20;
         }

         if (var13[0]) {
            ++var20;
         }
         break;
      case 3:
         var20 += (double)(4 - var19);
         if (var13[6]) {
            ++var20;
         }

         if (var13[0]) {
            ++var20;
         }

         if (var13[1]) {
            ++var20;
         }
         break;
      case 4:
         var20 += (double)(3 - var19);
         if (var13[6]) {
            ++var20;
         }

         if (var13[0]) {
            ++var20;
         }

         if (var13[1]) {
            ++var20;
         }

         if (var13[2]) {
            ++var20;
         }
         break;
      case 5:
         var20 += (double)(2 - var19);
         if (var13[6]) {
            ++var20;
         }

         if (var13[0]) {
            ++var20;
         }

         if (var13[1]) {
            ++var20;
         }

         if (var13[2]) {
            ++var20;
         }

         if (var13[3]) {
            ++var20;
         }
         break;
      case 6:
         var20 += (double)(1 - var19);
         if (var13[6]) {
            ++var20;
         }

         if (var13[0]) {
            ++var20;
         }

         if (var13[1]) {
            ++var20;
         }

         if (var13[2]) {
            ++var20;
         }

         if (var13[3]) {
            ++var20;
         }

         if (var13[4]) {
            ++var20;
         }
      }

      var9 -= var1.getDayOfWeek() + 1;
      if (!var13[6]) {
         ++var20;
      }

      for(int var16 = 1; var16 <= var1.getDayOfWeek(); ++var16) {
         if (!var13[var16 - 1]) {
            ++var20;
         }
      }

      var20 += (double)(var9 / 7 * 5);
      HashMap var21 = new HashMap();
      if (var3 != null) {
         int var17 = 0;

         while(var17 < var3.length) {
            switch(var3[var17].getDayOfWeek()) {
            default:
               if (com.aspose.cells.a.c.zk.b(var3[var17], var0) && com.aspose.cells.a.c.zk.c(var3[var17], var1)) {
                  int var18 = (int)CellsHelper.getDoubleFromDateTime(var3[var17], false);
                  if (var21.get(var18) == null) {
                     var21.put(var18, var18);
                     --var20;
                  }
               }
            case 0:
            case 6:
               ++var17;
            }
         }
      }

      return var10 ? -var20 : var20;
   }

   static Object a(DateTime var0, DateTime var1, DateTime[] var2, boolean var3) {
      double var4 = (double)((int)CellsHelper.getDoubleFromDateTime(var0, var3));
      double var6 = (double)((int)CellsHelper.getDoubleFromDateTime(var1, var3));
      int var8 = (int)(var6 - var4 + 1.0D);
      boolean var9 = false;
      if (var8 < 0) {
         var8 = -var8;
         var9 = true;
         DateTime var10 = var0;
         var0 = var1;
         var1 = var10;
         double var11 = var4;
         var4 = var6;
         var6 = var11;
         var8 = (int)(var11 - var4 + 1.0D);
      }

      if (a(var0, var1, var4, var6)) {
         if (var0.getDayOfWeek() == 0) {
            --var8;
         }

         if (var1.getDayOfWeek() == 6) {
            --var8;
         }

         return var9 ? -var8 : var8;
      } else {
         var8 -= 7 - var0.getDayOfWeek();
         double var15 = 0.0D;
         switch(var0.getDayOfWeek()) {
         case 0:
         case 1:
            var15 += 5.0D;
            break;
         default:
            var15 += (double)(6 - var0.getDayOfWeek());
         }

         var8 -= var1.getDayOfWeek() + 1;
         switch(var1.getDayOfWeek()) {
         case 0:
            break;
         case 6:
            var15 += 5.0D;
            break;
         default:
            var15 += (double)var1.getDayOfWeek();
         }

         var15 += (double)(var8 / 7 * 5);
         HashMap var12 = new HashMap();
         if (var2 != null) {
            int var13 = 0;

            while(var13 < var2.length) {
               switch(var2[var13].getDayOfWeek()) {
               default:
                  if (com.aspose.cells.a.c.zk.b(var2[var13], var0) && com.aspose.cells.a.c.zk.c(var2[var13], var1)) {
                     int var14 = (int)CellsHelper.getDoubleFromDateTime(var2[var13], false);
                     if (var12.get(var14) == null) {
                        var12.put(var14, var14);
                        --var15;
                     }
                  }
               case 0:
               case 6:
                  ++var13;
               }
            }
         }

         return var9 ? -var15 : var15;
      }
   }

   static Object a(Object[] var0, Workbook var1) {
      Object[][] var2 = (Object[][])((Object[][])var0[0]);
      Object[][] var3 = (Object[][])((Object[][])var0[1]);
      Object[][] var4 = (Object[][])((Object[][])var0[2]);
      Object[][] var5 = new Object[var2.length][];
      int var6 = var2[0].length;

      for(int var7 = 0; var7 < var2.length; ++var7) {
         var5[var7] = new Object[var6];

         for(int var8 = 0; var8 < var6; ++var8) {
            var5[var7][var8] = b(new Object[]{var2[var7][var8], var3[var7][var8], var4[var7][var8]}, var1);
         }
      }

      return var5;
   }

   static Object b(Object[] var0, Workbook var1) {
      int[] var2 = new int[3];

      int var3;
      for(var3 = 0; var3 < 3; ++var3) {
         switch(zamo.a(var0[var3].getClass())) {
         case 3:
            if ((Boolean)var0[var3]) {
               var2[var3] = 1;
            } else {
               var2[var3] = 0;
            }
            break;
         case 9:
            var2[var3] = (Integer)var0[var3];
            break;
         case 14:
            var2[var3] = (int)com.aspose.cells.a.c.zi.b(var0[var3]);
            break;
         case 16:
            switch(var3) {
            case 0:
               var2[0] = ((DateTime)var0[0]).getYear();
               continue;
            case 1:
               var2[1] = ((DateTime)var0[1]).getMonth();
               continue;
            case 2:
               var2[2] = ((DateTime)var0[2]).getDay();
            default:
               continue;
            }
         case 18:
            String var4 = (String)var0[var3];
            if (!zapb.d(var4)) {
               return zst.i;
            }

            var2[var3] = (int)com.aspose.cells.b.a.zn.a(var4);
            break;
         default:
            return zst.i;
         }
      }

      if ((double)var2[0] < 0.0D) {
         return zst.f;
      } else {
         var3 = var2[0];
         if (var3 < 1900) {
            var3 += 1900;
         }

         int var8 = var2[1];
         int var5 = var2[2];

         try {
            DateTime var6 = DateTime.a.addYears(var3 - 1).addMonths(var8 - 1).addDays((double)(var5 - 1));
            if (var6.getYear() < 1900) {
               return zst.f;
            } else {
               return CellsHelper.getDoubleFromDateTime(var6, var1.getSettings().getDate1904());
            }
         } catch (Exception var7) {
            return zst.f;
         }
      }
   }
}
